package com.cande.loki.jmh;

import org.HdrHistogram.Histogram;

import java.io.*;

public class HdrOut {
    public static void main(String[] args) {
        System.out.println("  dsada dsada   ".trim());

        // 指定要读取的文本文件路径
        String filePath = "C:\\Users\\Administrator\\Desktop\\dbtrr.txt";
        Histogram histogram = new Histogram( 999 * 1000L, 1);

        try {
            // 创建文件读取对象
            FileReader fileReader = new FileReader(filePath);
            BufferedReader bufferedReader = new BufferedReader(fileReader);

            // 读取文件内容并逐行输出
            String line;
            while ((line = bufferedReader.readLine()) != null) {

                if (!line.equals("")){
                    Long l =new  Double(Double.parseDouble(line.trim())* 1000000).longValue();
                    System.out.println(l);
                    histogram.recordValue(l);
                }
            }



            String outputPath = "histogram_output.txt";

            // 创建文件写入对象
            FileOutputStream fileOutputStream = new FileOutputStream(outputPath);

            PrintStream ps = new PrintStream(fileOutputStream);
            // 输出直方图分布到文件中
            histogram.outputPercentileDistribution(ps, 1d); // 输出到文件，每个百分位数之间间隔5个数字



            System.out.println("Histogram output to file successfully: " + outputPath);


            // 关闭文件读取对象
            bufferedReader.close();
            fileReader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
